﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using static System.Windows.SystemParameters;
using Microsoft.Win32;


namespace MyMediaPlayer
{
    internal class UT
    {

        internal void Suffle(List<string> lst)
        {
            Random rd = new Random();
            int n = lst.Count;
            for (int i = 0; i < n; i++)
            {
                // NextDouble returns a random number between 0 and 1.
                // ... It is equivalent to Math.random() in Java.
                int r = i + (int)(rd.NextDouble() * (n - i));
                string t = lst[r];
                lst[r] = lst[i];
                lst[i] = t;
            }

        }
    }
    internal class ClipBoardHelper
    {
        public event EventHandler<ClipBoardEvenArgs> ClipBoardChanged;
        Timer tmr;
        public ClipBoardHelper()
        {
            tmr = new Timer() { Interval = 10, Enabled = true };
            tmr.Tick += (sender, e) =>
            {
                List<string> lst = this.Get();
                if (lst != null && lst.Count > 0)
                {
                    ClipBoardEvenArgs ce = new ClipBoardEvenArgs();
                    ce.Files = lst;
                    this.OnClipBoardTextChanged(ce);

                }
            };
        }
        public void Send(string[] text)
        {
            Clipboard.SetText(string.Join(",", text, 0, text.Length) + ",Meepo_Player", TextDataFormat.CommaSeparatedValue);
        }
        private List<string> Get()
        {
            List<string> lst = null;
            if (Clipboard.ContainsText(TextDataFormat.CommaSeparatedValue) && Clipboard.GetText(TextDataFormat.CommaSeparatedValue).Contains("Meepo_Player"))
            {
                lst = Clipboard.GetText(TextDataFormat.CommaSeparatedValue).Split(',').ToList<string>();
                lst.RemoveAt(lst.Count - 1);
                Clipboard.Clear();
            }
            return lst;
        }
        protected virtual void OnClipBoardTextChanged(ClipBoardEvenArgs e)
        {
            EventHandler<ClipBoardEvenArgs> handler = this.ClipBoardChanged;
            if (handler != null)
            {
                handler(this, e);
            }
        }

    }
    internal sealed class ClipBoardEvenArgs : EventArgs
    {
        public List<string> Files { get; set; }
    }
    internal sealed class SizeHelper
    {
        private double ScaleXY { get; set; } = 1.777777;

        public SizeHelper(double width, double height)
        {
            double maxW, minW;
            maxW = PrimaryScreenWidth / this.ScaleXY;
            minW = 800 / this.ScaleXY;
            if (width <= maxW && width >= minW)
            {
                this.X = width * this.ScaleXY;
                this.Y = height * this.ScaleXY;
            }
            else if (width > maxW)
            {
                this.IsMax = true;
            }

        }
        public bool IsMax { get; set; }
        public double X { get; set; }
        public double Y { get; set; }

    }

    internal sealed class ToastNotificationHelper
    {
        private bool IsAble()
        {
            bool b = false;
            var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
            string ver = (string)reg.GetValue("ProductName");
            if (ver.Contains("Windows 10") || ver.Contains("Windows 8.0") || ver.Contains("Windows 8.1"))
                b = true;
            return b;
        }
    }
}
